package pers.kw;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;

/**
 * 消费者
 */
@Slf4j
@Component
public class RabbitMQListener {

    @RabbitListener(queues = RabbitMQConfig.DELAYED_QUEUE)
    public void receive(Message message) {
        log.info("1 当前时间：{},收到死信队列信息：{}", LocalDateTime.now(), new String(message.getBody(), StandardCharsets.UTF_8));
        //消息未被ack，rabbitmq重启后，消息会被重新消费
    }

    @RabbitListener(queues = RabbitMQConfig.DELAYED_QUEUE)
    public void receive2(Message message) {
        log.info("2 当前时间：{},收到死信队列信息：{}", LocalDateTime.now(), new String(message.getBody(), StandardCharsets.UTF_8));
        //消息未被ack，rabbitmq重启后，消息会被重新消费
    }
}
